/*
 * Copyright (C) 2008 Rob Cash
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.robcash.commons.event;

import java.util.EventObject;

/**
 * Task lifecycle event
 * @param T status type
 * @author Rob
 */
public class TaskEvent<T> extends EventObject {

    private T status;

    private int percentComplete = -1;

    public TaskEvent(Object task) {
        super(task);
    }

    /**
     * Get the task status
     * @return Task status
     */
    public T getStatus() {
        return status;
    }

    /**
     * Set the task status
     * @param status Task status
     */
    public void setStatus(T status) {
        this.status = status;
    }

    /**
     * Get the percent complete.
     * @return Percent complete is a value between 0 and 100 to
     * indicate the percent complete. A value of -1 indicates that the status is
     * unknown.
     */
    public int getPercentComplete() {
        return percentComplete;
    }

    /**
     * Set the percent complete. This should return a value between 0 and 100 to
     * indicate the percent complete. A value of -1 indicates that the status is
     * unknown.
     * @param percentComplete Percent complete as a value in the range -1 to 100
     * inclusive
     * @throws IllegalArgumentException Thrown if the percent complete is less
     * than -1 or greater than 100
     */
    public void setPercentComplete(int percentComplete) throws IllegalArgumentException {
        if ( percentComplete < -1 || percentComplete > 100 ) {
            throw new IllegalArgumentException("Percent complete must be in " +
                    "the range of -1 thru 100, inclusive");
        }
        this.percentComplete = percentComplete;
    }

}
